package com.tanquandan.askbackend.controller;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.tanquandan.askbackend.dto.R;
import com.tanquandan.askbackend.entity.Course;
import com.tanquandan.askbackend.service.ICourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    private ICourseService courseService;

    @GetMapping("listAll")
    public R<List<Course>> list(){
        return R.success(courseService.list());
    }

    @PostMapping
    public R<String> save(@RequestBody Course course){
        courseService.save(course);
        return R.success("课程新增成功");
    }

    @GetMapping("listRecommend")
    public R<List<Course>> recommend(HttpServletRequest request){
        HttpSession session = request.getSession();
        Long userId = (Long)session.getAttribute("user");
        return courseService.recommend(userId);
    }
}
